/*
 * $Id: MPHTGenerator.java,v 1.1 2003/05/17 08:55:41 znamenacek Exp $
 *
 * Copyright (c) Milan Jedlicka
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package net.sf.vofce.metapost;

import java.io.*;

/** This simle class generates METAPOST Headers and Tails of files and images.
  * @author Milan Jedlicka
  */
public class MPHTGenerator {

	private String generatedByComment;

	private PrintWriter stream;
	
	/** 
	 * Default constructor
	 * @param stream the stream where to generate headers and tails
	 */
	public MPHTGenerator(PrintWriter stream) {
		this.stream = stream;
	}

	/** 
	 * Set Generated By comment line. 
	 * @param 	by the <code>String</code> of comment
	 */
	public void setGeneratedByComment(String by) {
		this.generatedByComment = by;
	}
	
	/**
	 * Generates the header of the METAPOST file 
	 */
	public void doFileHeader() {
		if (generatedByComment != null) 
			doComment(generatedByComment + "\n");
			
		stream.println("input mp-tool ;");
		stream.println("input mp-spec ;\n");
	
	}

	/**
	 * Generates the header of the METAPOST image
	 */
	public void doPictHeader(int number) {
		stream.println("beginfig(" + number + ") ;");
	}

	/**
	 * Generates the tail of the METAPOST image
	 */
	public void doPictTail() {
		stream.println("endfig ;");
	}

	/**
	 * Generates the tail of the METAPOST file
	 */
	public void doFileTail() {
		stream.println("end.");
	}

	/**
	 * Generate some user comment.
	 * @param comment the <code>String</code> to use as comment
	 */
	public void doComment(String comment) {
		stream.println("\n% " + comment);
	}
}
